﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using SafoverWpfFw;
using System.Windows.Input;
using Safover.LidarCollector.Managers;
using Safover.LidarCollector.Models;
using Safover.LidarCollector.Config;
using Safover.Lidar.DataContract;

namespace Safover.LidarCollector.ViewModel
{
    public class OthersConfigViewModel : BaseViewModel
    {
        public static OthersConfigViewModel Instance => new OthersConfigViewModel();

        //public OthersConfig Model { get; set; }

        public ICommand SaveCommand { get; set; }

        /// <summary>
        /// 是否将扫描数据保存到数据库
        /// </summary>
        public bool SaveToDB { get; set; }

        /// <summary>
        /// 是否将扫描数据保存到文件
        /// </summary>
        public bool SaveToFile { get; set; } = true;

        public FileSaverVersion FileSaverVersion => AppConfig.FileSaverVersion;

        public string DataRootFolder { get; set; }

        public string PictureFilePath { get; set; }

        public bool UseSubBaseLine { get; set; }

        public float SubBaseLineStart { get; set; }

        public float SubBaseLineEnd { get; set; }

        public bool UseEmptyMining { get; set; }

        public float EmptyMiningDistance { get; set; }



        public double DefaultLatitude { get; set; }

        public double DefaultLongitude { get; set; }

        public double DefaultAltitude { get; set; }

        public string StationName { get; set; }

        public string StationNameEN { get; set; }

        public string StationId { get; set; }

        public string StationAbbreviation { get; set; }

        public string FileExtension { get; set; }

        private OthersConfigViewModel()
        {
            OthersConfig config = RuntimeConfigManager.Instance.OthersConfig;

            SaveToDB = config.SaveToDB;
            SaveToFile = config.SaveToFile;
            PictureFilePath = config.PictureFilePath;
            DataRootFolder = config.DataRootFolder;
            UseSubBaseLine = config.UseSubBaseLine;
            SubBaseLineStart = config.SubBaseLineStart;
            SubBaseLineEnd = config.SubBaseLineEnd;
            UseEmptyMining = config.UseEmptyMining;
            EmptyMiningDistance = config.EmptyMiningDistance;
            DefaultLatitude = config.DefaultLatitude;
            DefaultLongitude = config.DefaultLongitude;

            DefaultAltitude = config.DefaultAltitude;
            StationId = config.StationId;
            StationName = config.StationName;
            StationNameEN = config.StationNameEN;
            StationAbbreviation = config.StationAbbreviation;
            FileExtension = config.FileExtension;

            SaveCommand = new RelayCommand(Save);
        }

        private void Save()
        {
            var config = new OthersConfig
            {
                SaveToDB = SaveToDB,
                SaveToFile = SaveToFile,
                DataRootFolder = DataRootFolder,
                PictureFilePath = PictureFilePath,
                UseSubBaseLine = UseSubBaseLine,
                SubBaseLineStart = SubBaseLineStart,
                SubBaseLineEnd = SubBaseLineEnd,
                UseEmptyMining = UseEmptyMining,
                EmptyMiningDistance = EmptyMiningDistance,
                DefaultLatitude = DefaultLatitude,
                DefaultLongitude = DefaultLongitude,
                DefaultAltitude = DefaultAltitude,
                StationId = StationId,
                StationName = StationName,
                StationNameEN = StationNameEN,
                StationAbbreviation = StationAbbreviation,
                FileExtension = FileExtension,
            };

            RuntimeConfigManager.Instance.Save(config);

            DeviceManager.DeviceFactoryInstance.SetGpsDefault(DefaultLatitude, DefaultLongitude, DefaultAltitude);

            _ = DI.UI.ShowMessage(new MessageBoxDialogViewModel
            {
                Title = "提示",
                Message = "保存成功！"
            });
        }
    }


}
